"""
Copyright 2007, Thomas Dejanovic, Jay Shurtz.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
 
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

***********************************************************************

In Linux, the PYTHONPATH environment variable allows scripts to import
files in other directories.  If editing the PYTHONPATH is undesirable,
one common alternative is to add blank "__init__.py" files to those 
directories and import files using syntax like "from x.y import z".

However, neither approach works in Windows, and what does work
in Windows doesn't work in Linux.  The "hatch interface" (or register
access tool) needs to work on both operating systems, so a pure python
solution is needed.

One option is to release a "package," but this is undesirable as hatch 
is still "in progress."  Instead, the solution implemented here is to 
have one file in the top-level directory that knows where all the other 
files are and is capable of importing them; while every sub-directory 
has another file that points back to this main file, and is capable of
importing it.  In this way, every file in the design is capable of
importing any other file in the design via the top-level file. This 
is that top-level file.

"""

id = "$Id: hatch_structure.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/tags/taggle_release_3.0/hatch_structure.py $
# $Author: jayshurtz $
version = " ".join(id.split()[1:3])


from sys import path as syspath # os.sys.path (or sys.path) is a list of directories.
from os import path as ospath   # os.path is a module with functions such as ".join()".


absDir = ospath.split(ospath.abspath(__file__))[0]    # Get the absolute directory of this file ('hatch/tools').


# Define a list of hatch directories.
hatchDirs = []
hatchDirs.append(ospath.join(absDir, 'hatch_interface'))
hatchDirs.append(ospath.join(absDir, 'hatch_interface', 'pyserial-2.4'))    # XXX May not be the 2.4 version, import glob for wildcards ?
#hatchDirs.append(ospath.join(absDir, 'hatch_interface', 'pyserial-2.5-rc2'))
hatchDirs.append(ospath.join(absDir, 'hatch'))
hatchDirs.append(ospath.join(absDir, 'hatch', 'hatch_library'))
hatchDirs.append(ospath.join(absDir, 'hatch', 'hatch_nodes'))   # Ex: '/home/widentifi/hatch/tools/hatch/hatch_nodes'
hatchDirs.append(ospath.join(absDir, 'hatch', 'hatch_targets'))
hatchDirs.append(ospath.join(absDir, 'hatch', 'hatch_targets','verilog'))
hatchDirs.append(ospath.join(absDir, 'hatch', 'hatch_visitors'))


# Add hatch dirs to sys.path.
for _dir in hatchDirs:
    syspath.append(_dir)


# Imports now possible.
del syspath, ospath


